﻿<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>商品后台管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="./css/bootstrap.css">
    <link rel="stylesheet" href="./css/all.css">
    <link rel="stylesheet" href="./css/course_category.css">
</head>

<body>
    <div id="app">
        <nav class="navbar">
            <div class="container" >
                <div class="navbar-header">
                    <a class="navbar-brand" href="#" >
                        <img src="image/easy-pay.png">
                    </a>
                </div>
                <ul class="nav navbar-nav navbar-right" style="margin-top: 30px">
                    <li><a href="#"><span class="inner">首页</span></a></li>
                    <li>
                        <a href="#">
                            <span class="inner">商品管理</span></a>
                    </li>
                    <li>
                        <a href="#">
                            <span class="inner">购物车管理</span>
                        </a>
                    </li>

                    <li>
                        <a href="#">
                            <span class="inner">用户管理</span></a>
                    </li>
                </ul>
            </div>
        </nav>
        <div style="min-height: 400px">
            <div class="container">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4>商品管理-增加商品</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <label for="title" class="col-sm-3 control-label">
                                    商品标题</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="title" placeholder="在此输入商品标题" value="">
                                </div>
                                <div class="col-sm-1 red">*</div>
                            </div>
                            <div class="form-group">
                                <label for="content" class="col-sm-3 control-label">
                                    商品描述</label>
                                <div class="col-sm-8">
                                    <textarea name="" class="form-control" id="content" cols="101" rows="3"
                                        placeholder="在此输入商品描述"></textarea>
                                </div>
                                <div class="col-sm-1 red"></div>
                            </div>
                            <div class="form-group">
                                <label for="imagePath" class="col-sm-3 control-label">
                                    图片路径</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="imagePath" placeholder="在此输入图片路径"
                                        value="">
                                </div>
                                <div class="col-sm-1 red">*</div>
                            </div>
                            <div class="form-group">
                                <label for="price" class="col-sm-3 control-label">
                                    商品价格</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="price" placeholder="在此输入商品价格" value="">
                                </div>
                                <div class="col-sm-1 red">*</div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <p class="form-control-static text-danger" id="msg">在此显示错误信息</p>
                                </div>
                            </div>
                            <div style="text-align: right">
                                <button type="button" class="btn btn-primary" id="assure" @click="add">确定</button>
                                <button type="button" class="btn btn-default">取消</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <footer>
            <div class="container">
                <p class="text-center">易购集团</p>
                <p class="text-center">Copyright 2019</p>
            </div>
        </footer>
    </div>

</body>

</html>

<!--  提示，本题需要表单验证
如：单价必须输入纯数值，单价不能为负数
单价只可以是1-2位小数
/^(([1-9]\d+)|0)(\.\d{1,2})?$/.test()
 -->

<script src="./js/axios.min.js"></script>
<script>
    const assure=document.getElementById('assure')
    const msg=document.getElementById('msg')
    assure.onclick=function(){
        // 获取数据
        const title=document.getElementById('title').value
        const content=document.getElementById('content').value
        const imagePath=document.getElementById('imagePath').value
        const price=document.getElementById('price').value
        // 验证数据
        if(title===''){
            msg.innerHTML='商品的标题不能为空'
            return
        }
        if(imagePath===''){
            msg.innerHTML='图片路径不能为空'
            return
        }
        if(price===''){
            msg.innerHTML='商品的价格不能为空'
            return
        }
        if(!/^(([1-9]\d+)|0)(\.\d{1,2})?$/.test(price)){
            msg.innerHTML='商品的价格格式不正确'
            return
        }
        // 添加数据
        axios.post('http://localhost:8090/h9/goods/addGoods',{title,content,imagePath,price})
        .then(res=>{
            // alert(res.data.msg)
            if(res.data.success){
                msg.innerHTML='商品添加成功'
            }
        })
    }
</script>